package com.th.supcom.pds.drugsupply.client.widget;

import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.EventType;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.th.supcom.pds.common.client.model.icon.Resources;
import com.th.supcom.pds.drugsupply.client.common.PdsPropertyMaitainModuleEvents;

/**
 * 药品属性维护工具条
 * 
 * @author Zli
 */
public class DrugMaintainPanelToolBar extends ToolBar
{

    public DrugMaintainPanelToolBar ()
    {
        this.initButtons ();
    }

    private Button initBtn (final String tile, final EventType eventType, final AbstractImagePrototype icon)
    {// 按钮监听事件
        final Button btn = new Button (tile);
        btn.setIcon (icon);
        btn.addSelectionListener (new SelectionListener <ButtonEvent> ()
        {
            @Override
            public void componentSelected (final ButtonEvent be)
            {
                final AppEvent event = new AppEvent (eventType);
                Dispatcher.forwardEvent (event);
            }
        });
        return btn;
    }

    private void initButtons ()
    {
        this.add (initBtn ("新增", PdsPropertyMaitainModuleEvents.ADD_DRUG_INFO, Resources.s_ICONS.add ()));
        this.add (new SeparatorToolItem ());
        this.add (initBtn ("保存", PdsPropertyMaitainModuleEvents.EDIT_INFO, Resources.s_ICONS.save ()));
        this.add (new SeparatorToolItem ());
        this.add (initBtn ("刷新", PdsPropertyMaitainModuleEvents.REFRESH_DRUG_INFO, Resources.s_ICONS.refresh ()));
        this.add (new SeparatorToolItem ());

    }

}
